<<if ($defaulttext != "")>>
<div class="defaulttext" style="padding-top:14px;">
<<$defaulttext>>
</div>
<</if>>

<table class="searchtable" width="100%">
<tr class="input">
<td colspan=2 width="250px">
<<inputchoice value="<<$searchvalue>>" width=200 onclick="countryclicked()" name="country" itemservice="{pagename:'habroad',servicename:'getcountries'}" id="country">>
</td>
<td valign="top">
<input value="" name="ha_company">
</td>
<td valign="top">
<button onclick="searchClicked(false)">search</button>
</td>
<td width="30%" style="text-align:right;" valign="top">
<<if ($registertype == "5")>>
<<if ($hasCompanyProfile)>>
<a href="index.php?choice=profile">Update your company</a>
<<else>>
<a href="index.php?choice=profile">Register your company</a>
<</if>>
<<else if (!$loggedin)>>
<a href="index.php?choice=profile">Register your company</a>
<</if>>
</td>
</tr>

</tr>
</table>

<script>
var selectedComponent = "";

function countryclicked() {
    selectedComponent = "country";
}

jQuery("input[name='ha_company']").freetextsearch({
    dependantControl : jQuery("input#country"),
    sourcepage : "habroad",
    resultpage : "companyprofile",
    resultsubpage : "view",
    filterservice : "getcompanieslike",
    change : function() {
        selectedComponent = "company";
    },
    defaulttext : "Company name",
});

function searchClicked(newWindow) {
    if (selectedComponent == "country") {
        var input = jQuery("input[type='text'][name='country']").val();
        redirect("list_hacompanies", "viewlist", {
            selectedItem : input,
            enteredText : input,
            type : "country"
        }, newWindow);
    } else if (selectedComponent == "company") {
        var input = jQuery("select#ha_company_list").find("option:selected").val();
        if (input) {
            redirect("list_hacompanies", "viewlist", {
                selectedItem : jQuery("select#ha_company_list").find("option:selected").val(),
                enteredText : jQuery("input[name='ha_company']").val(),
                type : "company"
            }, newWindow);
        }
    }
}

</script>
